# 统计以球型病灶为前提，扩增数据后，每位病人的图像数量分布

import os
import glob
import matplotlib.pyplot as plt


path = 'D:/lung_cancer/data/data_augmentation/divide_csv/over_sampling_five/Slice/'

def statistic_number():
    patients = os.listdir(path)
    print(patients)

    num_list = []

    for i, item in enumerate(patients):
        one_path = path+item+'/CTSlice/'
        files = os.listdir(one_path)
        num = len(files)
        num_list.append(num)

        print(i, ' : ', num)


    # 绘制数值分布

    print(max(num_list))  # 33
    print(min(num_list))  # 3

    # 以【1， 35】作为横坐标，纵坐标为每个点出现的次数
    count_list = []
    for j in range(36):
        quan = num_list.count(j)
        count_list.append(quan)


    # 绘制直方图
    x_list = list(range(36))
    plt.bar(x_list, count_list, label='Quantity distribution')

    # plt.legend()
    plt.xlabel('number')
    plt.ylabel('value')

    plt.show()


if __name__ == '__main__':
    statistic_number()